home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************\
- | Purpose :: This module is responsible for initializing the program |
- | and entering the main event loop. |
- |-----------------------------------------------------------------------|
- | Copyright © Joe Pillera, 1990. All Rights Reserved. |
- \***********************************************************************/
-
- #include "demo.h"
-
- /***********************************************************************\
- | void main( void ) |
- |-----------------------------------------------------------------------|
- | Purpose :: To peform the routine initializations and enter the demo |
- | program's event loop. |
- |-----------------------------------------------------------------------|
- | Arguments :: None. |
- |-----------------------------------------------------------------------|
- | Returns :: Exits to Finder. |
- \***********************************************************************/
-
- Boolean program_done;
-
- void main()
- {
- /* Perform routine initializations */
- MoreMasters ();
- MoreMasters ();
- MoreMasters ();
- FlushEvents (-1, 0);
- InitGraf (&thePort);
- InitFonts ();
- InitWindows ();
- TEInit ();
- InitMenus ();
- InitDialogs (NIL);
- InitCursor ();
-
- /* Load in the menu bar */
- ClearMenuBar();
- SetMenuBar (GetNewMBar (MBarID));
- AddResMenu (GetMHandle (AppleID), 'DRVR');
- DrawMenuBar ();
-
- /* Enter the main event loop until done */
- program_done = FALSE;
- Do_Event_Loop();
- }
-
-
-
-
- /***********************************************************************\
- | void Do_Event_Loop( void ) |
- |-----------------------------------------------------------------------|
- | Purpose :: To implement the main event loop. |
- |-----------------------------------------------------------------------|
- | Arguments :: None. |
- |-----------------------------------------------------------------------|
- | Returns :: void |
- \***********************************************************************/
-
- void Do_Event_Loop()
- {
- char ch; /* Key pressed in Ascii */
- short code; /* Determine event type */
- short theMenu,theItem; /* Menu list and item selected */
- short chCode; /* Key code */
- long mResult; /* Menu list and item selected values */
- WindowPtr whichWindow; /* See which window for event */
- EventRecord myEvent; /* Event record for all events */
- TEHandle theInput; /* Used in text edit selections */
- GrafPtr SavePort; /* Place to save current drawing port */
-
- do {
- SystemTask();
- if (GetNextEvent(everyEvent, &myEvent)) {
- code = FindWindow(myEvent.where, &whichWindow);
-
- switch (myEvent.what) {
- case mouseDown:
- if (code == inMenuBar) {
- mResult = MenuSelect(myEvent.where);
- Do_Command(mResult);
- }
-
- if (code == inContent) {
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else
- SetPort(whichWindow);
- }
-
- if (code == inSysWindow)
- SystemClick(&myEvent, whichWindow);
- break;
-
- case keyDown:
- case autoKey:
- ch = myEvent.message & charCodeMask;
- if (myEvent.modifiers & cmdKey) {
- mResult = MenuKey(ch);
- theMenu = HiWord(mResult);
- if (theMenu == FileID)
- Do_Command(mResult);
- }
- break;
-
- case updateEvt:
- whichWindow = (WindowPtr)myEvent.message;
- GetPort(&SavePort);
- BeginUpdate(whichWindow);
- SetPort(whichWindow);
- EndUpdate(whichWindow);
- SetPort(SavePort);
- break;
-
- case diskEvt:
- if (HiWord(myEvent.message) != 0) {
- myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);
- myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);
- InitCursor();
- theItem = DIBadMount(myEvent.where, myEvent.message);
- }
- break;
-
- case activateEvt:
- if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag))
- SelectWindow(whichWindow);
- break;
-
-
- default:
- break;
-
- }
- }
- }
- while (program_done == FALSE);
- }
-